<template>
    <div class="" v-if="state !== 'hidden'">
        <el-form ref="form" :model="form" :label-width="'write' == state ? '115px' : 'auto'"
                 :class="'write' == state ? 'write-form' : 'read-form'"
                 :label-position="'write' == state ? 'top' : 'left'">
            <div class="card-wrap flex-column justify-end card-padding">
                <div class="card-title-wrap">
                    <span>车辆信息</span>
                    <span></span>
                </div>

                <div class="container_content" v-if="form.carList && form.carList.length > 0">
                    <el-table border :data="form.carList" style="width: 100%">
                        <el-table-column label="操作" min-width="160"
                                         align="center" v-if="1==form.isNoInstall"
                                         class-name="small-padding fixed-width">
                            <template slot-scope="scope">
                                <e-button size="mini" type="text"
                                          @click="handleUpload(scope.row, scope.$index)">
                                    {{ 'write' == state?(scope.row.noInstallProveId!==undefined&&scope.row.noInstallProveId!==null&&scope.row.noInstallProveId!==''?'附件已上传':'上传免安装证明'):'查看免安装证明' }}
                                </e-button>
                            </template>
                        </el-table-column>

                        <el-table-column v-if="form.flowBusinessId" label="批次号" align="center"
                                         :min-width="260" show-overflow-tooltip>
                            <template slot-scope="scope">
                                <span>{{form.flowBusinessId}}</span>
                            </template>
                        </el-table-column>

                        <el-table-column v-for="item in tableItem" :label="item.label" align="center"
                                         :min-width="item.minWidth" show-overflow-tooltip>
                            <template slot-scope="scope">
                                <template v-if="!item.filterable">
                                  <span
                                      :class="'contractReportNumber'==item.prop||'procurementReportNumber'==item.prop?'table-blue-text':''"
                                      @click="goDetail(item, scope.row)">
                                    {{ scope.row[item.prop] | filterNull }}</span>
                                </template>
                                <template v-else>
                                    <span>{{ item.filter(scope.row) }}</span>
                                </template>
                            </template>
                        </el-table-column>

                    </el-table>
                </div>

                <CarBaseInfo v-else :form="form"></CarBaseInfo>
            </div>

            <div class="card-wrap flex-column justify-end card-padding">
                <div class="card-title-wrap">
                    <span>GPS安装信息</span>
                    <span></span>
                </div>

                <el-row :gutter="30">
                    <el-col :span="24">
                        <el-form-item label="GPS是否免安装:" prop="isNoInstall" :rules="
                                'write' == state
                                    ? {
                                          required: true,
                                          message: '请选择GPS是否免安装',
                                          trigger: 'change',
                                          validator: (rule, value, callback) =>
                                              validData(
                                                  rule,
                                                  form.isNoInstall,
                                                  callback
                                              ),
                                      }
                                    : {}
                            ">

                            <el-radio-group @change="inputChange" v-if="'write' == state" type="datetime" v-model="form.isNoInstall">
                                <el-radio :label="0">否</el-radio>
                                <el-radio :label="1">是</el-radio>
                            </el-radio-group>
                            <span v-else>{{ 0==form.isNoInstall?'否':1==form.isNoInstall?'是':'--' }}</span>
                        </el-form-item>
                    </el-col>

                    <template v-if="0==form.isNoInstall">

                        <el-col :span="8">
                            <el-form-item label="预约安装时间:" prop="installTime" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请选择安装时间',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.installTime,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-date-picker v-model="form.installTime" style="width: 100%"
                                                value-format="yyyy-MM-dd HH:mm:ss" v-if="'write' == state" type="datetime"
                                                placeholder="请选择安装时间"></el-date-picker>
                                <span v-else>{{
                                        form.installTime | filterNull
                                    }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="安装地点:" prop="installAddress" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入安装地点',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.installAddress,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
    <!--                            <el-input maxlength="50" v-model="form.installAddress" clearable v-if="'write' == state"-->
    <!--                                      placeholder="请输入安装地点"></el-input>-->

    <!--                            v-model="form.installAddress"-->
                                <ProvinceCityDistrict v-if="'write' == state"
                                              placeholder="请选择安装地点" v-model="form.installAddressCode"
                                              @change="citySelectionChange"></ProvinceCityDistrict>

                                <span v-else>{{ form.installAddress | filterNull }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="安装具体地址:" prop="installAddressInfo" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入安装具体地址',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.installAddressInfo,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-input maxlength="50" v-model="form.installAddressInfo" clearable v-if="'write' == state"
                                          placeholder="请输入安装具体地址"></el-input>
                                <span v-else>{{ form.installAddressInfo | filterNull }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="GPS品牌:" prop="gpsBrand" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入GPS品牌',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.gpsBrand,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <!-- <el-input maxlength="50" v-model="form.gpsBrand" clearable v-if="'write' == state" placeholder="请输入GPS品牌"></el-input> -->
                                <el-select filterable v-if="'write' == state" v-model="form.gpsBrand" clearable
                                           style="width: 100%">
                                    <template v-for="dict in dict.type.gps_brand_list">
                                        <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
                                    </template>
                                </el-select>
                                <span v-else>{{ form.gpsBrand | filterNull }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="GPS金额:" prop="gpsPrice" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入GPS金额',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.gpsPrice,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-input v-model="form.gpsPrice" clearable v-thousand v-if="'write' == state"
                                          @change="inputChange"
                                          @input="value=>{if(isNaN(form.gpsPrice)) { form.gpsPrice = '' }; if(form.gpsPrice.indexOf('.')>0){form.gpsPrice=form.gpsPrice.slice(0,form.gpsPrice.indexOf('.')+3)} form.gpsPrice = form.gpsPrice.replace(new RegExp(`^\\D*(\\d{8}(?:\\.\\d{0,2})?).*$`, ''), '$1')}"
                                          placeholder="请输入GPS金额"></el-input>
                                <span v-else>{{ form.gpsPrice | filterNull }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8" v-if="form.carList && form.carList.length > 0">
                            <el-form-item label="合计GPS金额:" prop="totalAmount" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入合计GPS金额',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.totalAmount,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-input v-model="form.totalAmount" clearable v-thousand v-if="'write' == state" disabled ref="totalAmount"
                                          placeholder="系统根据批量车辆数量*GPS金额计算"></el-input>
                                <span v-else>{{ form.totalAmount | filterNull }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="设备类型:" prop="equipmentType" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请选择设备类型',
                                              trigger: 'change',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.equipmentType,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-select @change="$forceUpdate()" filterable v-if="'write' == state" v-model="form.equipmentType" clearable
                                           style="width: 100%">
                                    <template v-for="dict in dict.type.gps_device_type">
                                        <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
                                    </template>
                                </el-select>
                                <span v-else><dict-tag :options="dict.type.gps_device_type"
                                                       :value="form.equipmentType"/></span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8" v-if="
                                2 == form.equipmentType || 3 == form.equipmentType
                            ">
                            <el-form-item label="无线个数:" prop="wirelessCount">

                                <el-select filterable v-if="'write' == state" v-model="form.wirelessCount" clearable
                                           @change="inputChange"
                                           style="width: 100%">
                                    <template v-for="dict in installNum">
                                        <el-option :label="dict.name" :value="dict.value" :key="dict.value"></el-option>
                                    </template>
                                </el-select>

    <!--                            <el-input v-if="'write' == state" type="text"-->
    <!--                                      @input="value=>{form.wirelessCount=value.replace(/[^\d]/g,''), $forceUpdate}"-->
    <!--                                      :maxlength="11" v-model="form.wirelessCount" clearable-->
    <!--                                      placeholder="请输入无线个数"></el-input>-->
                                <span v-else>{{
                                        form.wirelessCount | filterNull
                                    }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8" v-if="
                                1 == form.equipmentType || 3 == form.equipmentType
                            ">
                            <el-form-item label="有线个数:" prop="wiredCount">
                                <el-select filterable v-if="'write' == state" v-model="form.wiredCount" clearable
                                           @change="inputChange"
                                           style="width: 100%">
                                    <template v-for="dict in installNum">
                                        <el-option :label="dict.name" :value="dict.value" :key="dict.value"></el-option>
                                    </template>
                                </el-select>
    <!--                            <el-input v-if="'write' == state" type="text"-->
    <!--                                      @input="value=>{form.wiredCount=value.replace(/[^\d]/g,''), $forceUpdate}"-->
    <!--                                      :maxlength="11" v-model="form.wiredCount" clearable-->
    <!--                                      placeholder="请输入有线个数"></el-input>-->
                                <span v-else>{{
                                        form.wiredCount | filterNull
                                    }}</span>
                            </el-form-item>
                        </el-col>


                        <el-col :span="8" v-if="form.carList && form.carList.length > 0 && (1 == form.equipmentType || 3 == form.equipmentType)">
                            <el-form-item label="合计有线设备数量:" prop="wiredTotalCount">
                                <el-input v-model="form.wiredTotalCount" clearable v-if="'write' == state" disabled ref="wiredTotalCount"
                                          placeholder="系统根据批量车辆数量*有线安装数量计算"></el-input>
                                <span v-else>{{ form.wiredTotalCount | filterNull }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8" v-if="form.carList && form.carList.length > 0 && (2 == form.equipmentType || 3 == form.equipmentType)">
                            <el-form-item label="合计无线设备数量:" prop="wirelessTotalCount">
                                <el-input v-model="form.wirelessTotalCount" clearable v-if="'write' == state" disabled ref="wirelessTotalCount"
                                          placeholder="系统根据批量车辆数量*无线安装数量计算"></el-input>
                                <span v-else>{{ form.wirelessTotalCount | filterNull }}</span>
                            </el-form-item>
                        </el-col>


<!--                        <el-col :span="8" v-if="form.carList && form.carList.length > 0">-->
<!--                            <el-form-item label="合计安装设备数量:" prop="totalCount">-->
<!--                                <el-input v-model="form.totalCount" clearable v-if="'write' == state" disabled ref="totalCount"-->
<!--                                          placeholder="系统根据批量车辆数量*安装数量计算"></el-input>-->
<!--                                <span v-else>{{ form.totalCount | filterNull }}</span>-->
<!--                            </el-form-item>-->
<!--                        </el-col>-->

                        <el-col :span="8">
                            <el-form-item label="现场联系人:" prop="sceneContacts" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入现场联系人',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.sceneContacts,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-input maxlength="50" v-model="form.sceneContacts" clearable v-if="'write' == state"
                                          placeholder="请输入现场联系人"></el-input>
                                <span v-else>{{
                                        form.sceneContacts | filterNull
                                    }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="GPS设备服务期限:" prop="gpsServicePeriod" :rules="
                                    'write' == state
                                        ? {
                                              required: true,
                                              message: '请输入GPS设备服务期限',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.gpsServicePeriod,
                                                      callback
                                                  ),
                                          }
                                        : {}
                                ">
                                <el-select filterable v-if="'write' == state" v-model="form.gpsServicePeriod" clearable
                                           style="width: 100%">
                                    <el-option label="1年" value="1年" key="1年"></el-option>
                                    <el-option label="2年" value="2年" key="2年"></el-option>
                                    <el-option label="3年" value="3年" key="3年"></el-option>
                                </el-select>
                                <!--                            <el-input-->
                                <!--                                v-model="form.gpsServicePeriod"-->
                                <!--                                clearable-->
                                <!--                                v-if="'write' == state"-->
                                <!--                                @input="value=>{form.gpsServicePeriod=value.replace(/[^\d]/g,''), $forceUpdate}" :maxlength="11"-->
                                <!--                                placeholder="请输入GPS设备服务期限"-->
                                <!--                            ></el-input>-->
                                <span v-else>{{
                                        form.gpsServicePeriod | filterNull
                                    }}</span>
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item label="现场联系电话:" prop="sceneContactsTel" :rules="
                                    'write' == state
                                        ? [{
                                              required: true,
                                              message: '请输入现场联系电话',
                                              trigger: 'blur',
                                              validator: (rule, value, callback) =>
                                                  validData(
                                                      rule,
                                                      form.sceneContactsTel,
                                                      callback
                                                  ),
                                          }, { pattern:  /^1[3456789]\d{9}$/, message: '联系电话格式不正确', trigger: 'blur' }]
                                        : {}
                                ">
                                <el-input v-model="form.sceneContactsTel" clearable maxlength="11" v-if="'write' == state"
                                          @input="value=>form.sceneContactsTel=value.replace(/[^\d]/g,'')"
                                          placeholder="请输入现场联系电话"></el-input>
                                <span v-else>{{
                                        form.sceneContactsTel | filterNull
                                    }}</span>
                            </el-form-item>
                        </el-col>
                    </template>

                    <el-col :span="24" v-if="1==form.isNoInstall && (form.carList === undefined || form.carList === null || form.carList === '' || form.carList === [])">
                        <el-form-item label="GPS免安装证明:" prop="noInstallProveId" style="width: 100%"
                                      :rules="
                                        'write' == state
                                            ? {
                                                  required: true,
                                                  message: '请上传GPS免安装证明',
                                                  trigger: 'change',
                                                  validator: (rule, value, callback) =>
                                                      validData(
                                                          rule,
                                                          form.noInstallProveId,
                                                          callback
                                                      ),
                                              }
                                            : {}
                                    ">
                            <ImageCommon :disabled="'write' != state" :up-type="2" info="选择附件" :limit="20"
                                         v-model="form.noInstallProveId"></ImageCommon>
                        </el-form-item>
                    </el-col>

                </el-row>
            </div>
            <div class="card-wrap flex-column justify-end card-padding" v-if="0==form.isNoInstall">
                <div class="card-title-wrap">
                    <span>备注</span>
                    <span></span>
                </div>
                <el-row :gutter="30">
                    <el-col :span="24">
                        <el-form-item label="上传照片:" prop="imageOss" style="width: 100%">
                            <ImageCommon :disabled="'write' != state" :up-type="2" info="选择附件" :limit="9"
                                         v-model="form.imageOss"></ImageCommon>
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="备注:" prop="remark">
                            <el-input maxlength="500" v-if="'write' == state" type="textarea" v-model="form.remark"
                                      clearable placeholder="请输入备注"></el-input>
                            <span v-else>{{ form.remark | filterNull }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
            </div>
        </el-form>

        <el-dialog :title="'write' == state?'上传免安装证明':'查看免安装证明'" :visible.sync="publicOpen" append-to-body width="45%">

            <span v-if="'write' !== state && (selObj.noInstallProveId==undefined||selObj.noInstallProveId==null||selObj.noInstallProveId=='')">暂无数据</span>
            <ImageCommon v-else :disabled="'write' !== state" @input="imagechange"
                         :up-type="2" info="选择附件" :limit="9" v-model="selObj.noInstallProveId"></ImageCommon>

            <div slot="footer">
                <el-button type="primary" @click="publicOpen=false">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import CarBaseInfo from "@/views/GPSManage/components/carBaseInfo.vue";
import {OrderParam} from "@/api/finance/manage/collect/api";
import {orderCarParam} from "@/api/gps/gpsList";
import ProvinceCityDistrict from "@/components/ProvinceCityDistrict/index.vue";
import {isEmpty} from "lodash";

export default {
    components: {ProvinceCityDistrict, CarBaseInfo},
    dicts: [
        "gps_workorder_status",
        "quota_rent_type",
        "gps_workorder_type",
        "gps_device_type",
        "gps_brand_list",
        "car_business_type"
    ],
    props: {
        value: {
            default: {},
        },
        state: {
            default: "write",
        },
    },
    computed: {
        form: {
            get() {
                return this.value;
            },
            set(value) {
                this.$emit("input", value);
            },
        },
    },
    watch: {
        value:{
            handler(val){
                if(this.firstEnter && val && val.carList && val.carList.length>0){
                    this.firstEnter = false
                    this.inputChange()
                }
            },
            deep:true,
            immediate:true
        }
    },
    data() {
        return {
            firstEnter:false,
            tableItem: [],
            installNum:[
                {
                    name:"1",
                    value:1
                },
                {
                    name:"2",
                    value:2
                },
                {
                    name:"3",
                    value:3
                },
                {
                    name:"4",
                    value:4
                },
                {
                    name:"5",
                    value:5
                }
            ],
            publicOpen: false,
            selObj: {
                noInstallProveId:''
            },
        };
    },
    mounted() {
        this.$nextTick(() => {
            if ("write" == this.state) {
                this.form.equipmentType = "3";
                this.form.wiredCount = 1;
                this.form.wirelessCount = 1;
                this.form.imageOss = "";

                this.inputChange()
            }
        });

        this.initTable();
    },
    methods: {
        imagechange(val){
            console.log('imagechange', val, this.selObj)
            if(this.selObj){
                let find = this.form.carList.find(item=>this.selObj.carId==item.carId);
                if(find){
                    find.noInstallProveId = this.selObj.noInstallProveId
                }
            }
        },
        inputChange() {
            if(this.form.carList && this.form.carList.length>0){
                let num = this.form.carList.length;


                if (this.form.gpsPrice && num) {
                    this.$set(this.form, 'totalAmount', (Number(this.form.gpsPrice) * num).toFixed(2))
                } else {
                    this.$set(this.form, 'totalAmount', null)
                }

                // if(this.form.wirelessCount || this.form.wiredCount){
                //     this.$set(this.form, 'totalCount', Number((Number(this.form.wirelessCount)+Number(this.form.wiredCount)) * num))
                // }else {
                //     this.$set(this.form, 'totalCount', null)
                // }

                if(this.form.wiredCount){
                    this.$set(this.form, 'wiredTotalCount', Number(Number(this.form.wiredCount) * num))
                }else {
                    this.$set(this.form, 'wiredTotalCount', null)
                }

                if(this.form.wirelessCount){
                    this.$set(this.form, 'wirelessTotalCount', Number(Number(this.form.wirelessCount) * num))
                }else {
                    this.$set(this.form, 'wirelessTotalCount', null)
                }

                this.$forceUpdate()

                this.$nextTick(() => {
                    let el = this.$refs["totalAmount"]
                    el?.$refs?.input?.dispatchEvent(new Event('focus'));
                    el?.$refs?.input?.dispatchEvent(new Event('blur'));
                })
            }

        },
        citySelectionChange(val) {
            console.log('val', val)
            if (val.length > 0) {
                // const nodes = Array.from(val, item => ({
                //     value: item.value,
                //     label: item.label,
                //     pv: item.parent.value,
                //     pl: item.parent.label
                // }))
                // this.form.provinceId = nodes[0].pv
                // this.form.provinceName = nodes[0].pl
                // this.form.cityId = nodes[0].value
                // this.form.cityName = nodes[0].label
                this.form.installAddressCode = val[0]?.path?.join(",")??""
                this.form.installAddress = val[0]?.parent?.parent?.label + val[0]?.parent?.label + val[0].label
            } else {
                // this.form.provinceId = null
                // this.form.provinceName = null
                // this.form.cityId = null
                // this.form.cityName = null
                this.form.installAddressCode = ""
                this.form.installAddress = null
            }

            this.$forceUpdate()
            this.$refs.form.validateField(["installAddress"]);
            this.$nextTick(()=>{
                this.$refs.form.validateField(["installAddress"]);
            })

        },

        handleUpload(row, index) {
            this.publicOpen = true
            this.selObj = row
        },

        goDetail(item, row) {
            if ('contractReportNumber' == item.prop) {
                if (!row.mainOrderNo) {
                  return
                }

                orderCarParam(row.mainOrderNo)
                    .then(res => {
                        if (res.code == 200) {

                            this._toPage({
                                name: "SuborderDetail",
                                query: {
                                    id: res.data.orderCarId,
                                    orderId: res.data.orderCarCode
                                },
                            });

                            // this.$router.push({
                            //     name: 'OrderDetails',
                            //     query: {
                            //         type: res.data.carType,
                            //         beFrom: 'OrderView',
                            //         orderId: res.data.orderId,
                            //         preOrderId: res.data.preOrderId,
                            //         calcSchemeId: res.data.calcSchemeId,
                            //         isMenu: this.$route.query.isMenu,
                            //     },
                            // })
                        } else {
                            throw new Error(res);
                        }
                    })

                // OrderParam(row.mainOrderNo)
                //   .then(res => {
                //     if (res.code == 200) {
                //       this.$router.push({
                //         name: 'OrderDetails',
                //         query: {
                //           type: res.data.carType,
                //           beFrom: 'OrderView',
                //           orderId: res.data.orderId,
                //           preOrderId: res.data.preOrderId,
                //           calcSchemeId: res.data.calcSchemeId,
                //           isMenu: this.$route.query.isMenu,
                //         },
                //       })
                //     } else {
                //       throw new Error(res);
                //     }
                //   })
            } else if ('procurementReportNumber' == item.prop) {
                if (2 == row.purchaseSource) {
                    //订单
                    this._toPage({
                        name: "OrderPurchase",
                        query: {
                            purchaseOrderId: row.purchaseOrderId,
                            type: "detail",
                            pageType: "订单采购详情",
                        },
                    });
                } else if (1 == row.purchaseSource) {
                    this._toPage({
                        name: "PurchaseAdd",
                        query: {
                            purchaseOrderId: row.purchaseOrderId,
                            type: "detail",
                            pageType: "采购详情",
                        },
                    });
                }
            }
        },

        initTable() {
            this.tableItem = [
                {
                    label: "车架号",
                    prop: "vinNo",
                    minWidth: "180",
                    type: "text",
                },
                {
                    label: "车牌号",
                    prop: "carNo",
                    type: "text",
                    minWidth: "115",
                },
                {
                    label: "品牌/车型/车款",
                    prop: "brandName",
                    type: "text",
                    minWidth: "310",
                    filterable: true,
                    filter: (val) => {
                        return (
                            val.brandName +
                            "/" +
                            val.seriesName +
                            "/" +
                            val.modelName
                        );
                    },
                },
                {
                    label: "车辆产权",
                    prop: "propertyRightName",
                    type: "text",
                    minWidth: "210",
                },
                {
                    label: "车辆归属",
                    prop: "ascription",
                    type: "text",
                    minWidth: "210",
                },
                {
                    label: "车辆运营",
                    prop: "operationsName",
                    type: "text",
                    minWidth: "150",
                },
                {
                    label: "车辆大区",
                    prop: "region",
                    type: "text",
                    minWidth: "150",
                },
                {
                    label: "合同禀议编号",
                    prop: "contractReportNumber",
                    type: "text",
                    minWidth: "210",
                },
                {
                    label: "合同开始日期",
                    prop: "contractStartTime",
                    type: "text",
                    minWidth: "150",
                },
                {
                    label: "合同结束日期",
                    prop: "contractEndTime",
                    type: "text",
                    minWidth: "150",
                },
                {
                    label: "客户名称",
                    prop: "customerName",
                    type: "text",
                    minWidth: "150",
                },
                {
                    label: "采购禀议编号",
                    prop: "procurementReportNumber",
                    type: "text",
                    minWidth: "210",
                },
                {
                    label: "产品类型",
                    prop: "contractType",
                    type: "text",
                    minWidth: "180",
                    filterable: true,
                    filter: (val) => {
                        let result = [];
                        this.dict.type.quota_rent_type?.map((item) => {
                            if (item.value * 1 == val.contractType) {
                                result.push(item.label);
                            }
                        });
                        return result && result?.join("/");
                    },
                },
                {
                    label: "车辆状态",
                    prop: "businessType",
                    type: "text",
                    minWidth: "180",
                    filterable: true,
                    filter: (val) => {
                        let result = [];
                        this.dict.type.car_business_type?.map((item) => {
                            if ((item.value * 1) == val.businessType) {
                                result.push(item.label);
                            }
                        });
                        return result && result?.join("/");
                    },
                },
            ];
        },

        validData(rule, value, callback) {
            if (rule.required && (value===undefined || value===null || value === '' || value === [])) {
                // this.$modal.msgError(`未填写${value}`);
                callback(new Error(rule.message));
            } else {
                callback();
            }
        },

        async valid() {

            if (this.form.carList && this.form.carList.length > 0) {
                this.form.carIds = this.form.carList.map((item) => {
                    return item.carId;
                });
                this.form.workIds = this.form.carList.map((item) => {
                    return item.id;
                });

                if(1==this.form.isNoInstall){
                    //免安装
                    let find = this.form.carList.find(item=>item.noInstallProveId===undefined||item.noInstallProveId===null||item.noInstallProveId===''||item.noInstallProveId===[]);
                    if(find){
                        this.$modal.msgError("请上传免安装证明")
                        return
                    }
                }

            } else {
                this.form.carIds = [this.form.carId];
                this.form.workIds = [this.form.id];
            }

            return new Promise((resolve) => {
                if ('write' == this.state) {
                    this.$refs["form"].validate(valid => {
                        resolve(valid);
                    });
                } else {
                    resolve(true)
                }
            });
        },
    },
};
</script>

<style lang="scss" scoped>
::v-deep .el-form--label-top .el-form-item__label {
    padding: 0;
}

::v-deep .read-form .el-form-item__label-wrap,
::v-deep .read-form .el-form-item__content {
    margin-left: 0 !important;
}

.el-descriptions {
    margin: 0 -15px;
}
</style>
